﻿@model ExcellentCRM.DataService.Models.ContactRecord

@using (Ajax.BeginForm("ContactRecord", "StuClient",
                       new AjaxOptions {HttpMethod = "post", OnSuccess = "saveContactSucc"},
                       new { @class = "form-horizontal", id = "contactForm" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <div class="alert alert-error fade in hide">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <div class="alert-content"></div>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="control-group">
                @Html.LabelFor(m => m.Comment, new { @class = "control-label" })
                <div class="controls">
                    @Html.TextAreaFor(m => m.Comment, 5, 50, null)
                </div>
            </div>
            <div class="control-group hidden">
                <div class="controls">
                    <input type="submit" value="保存" class="btn btn-primary"/>
                    @Html.HiddenFor(m => m.Id)
                    @Html.HiddenFor(m => m.ConsultantId)
                    @Html.HiddenFor(m => m.ContactStuId)
                </div>
            </div>
        </div>
    </div>
}
<script type="text/javascript">
    $(function () {
        $.validator.unobtrusive.parse('#contactForm');
    });

    function saveSucc(result) {
        if (!result || (!result.success && !result.message)) {
            alert('保存失败，未知原因');
            return;
        }
        var $alertContain = $('#changePassForm .alert'),
            $alertContent = $alertContain.find('.alert-content');
        if (!result.success && result.message) {
            $alertContent.html(result.message);
            $alertContain.removeClass('alert-success hide').addClass('alert-error').alert();
            return;
        }
        if (result.success) {
            $alertContent.html('保存完成');
            $alertContain.removeClass('alert-error hide').addClass('alert-success').alert();
            $('#contactForm #Id').val(result.expandos.id);
        }
    }
</script>